Java Code Examples for com.l2fprod.common.swing.PercentLayout

The following examples show how to use com.l2fprod.common.swing.PercentLayout. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
JPanel makeOutlookPanel(int alignment) {
  JOutlookBar outlook = new JOutlookBar();
  outlook.setTabPlacement(JTabbedPane.LEFT);
  addTab(outlook, "Folders");
  addTab(outlook, "Backup");

  // show it is possible to add any component to the bar
  JTree tree = new JTree();
  outlook.addTab("A JTree", outlook.makeScrollPane(tree));

  outlook.addTab("Disabled", new JButton());
  outlook.setEnabledAt(3, false);
  outlook.setAllTabsAlignment(alignment);
  
  JPanel panel = new JPanel(new PercentLayout(PercentLayout.HORIZONTAL, 3));
  panel.add(outlook, "100");
  return panel;
}
 
Example 2
public ChooseDirectory() {
  setLayout(new PercentLayout(PercentLayout.VERTICAL, 3));

  if (System.getProperty("javawebstart.version") != null) {   
    JTextArea area = new JTextArea(RESOURCE.getString("message.webstart"));
    LookAndFeelTweaks.makeMultilineLabel(area);
    add(area);
  }

  final JButton button = new JButton(RESOURCE.getString("selectDirectory"));
  add(button);
  button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      selectDirectory(button, null);
    }
  });
}
 
Example 3
public void installUI(JComponent c) {
  super.installUI(c);
  taskPane = (JTaskPane)c;
  taskPane.setLayout(new PercentLayout(PercentLayout.VERTICAL, 14));
  taskPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
  taskPane.setOpaque(true);

  if (taskPane.getBackground() == null
    || taskPane.getBackground() instanceof ColorUIResource) {
    taskPane
      .setBackground(UIManager.getColor("TaskPane.background"));
  }
  
  useGradient = UIManager.getBoolean("TaskPane.useGradient");
  if (useGradient) {
    gradientStart = UIManager
    .getColor("TaskPane.backgroundGradientStart");
    gradientEnd = UIManager
    .getColor("TaskPane.backgroundGradientEnd");
  }
}
 
Example 4
void addTab(JOutlookBar tabs, String title) {
  JPanel panel = new JPanel();
  panel.setLayout(new PercentLayout(PercentLayout.VERTICAL, 0));
  panel.setOpaque(false);

  String[] buttons = new String[] {"Inbox", "icons/outlook-inbox.gif",
    "Outbox", "icons/outlook-outbox.gif", "Drafts", "icons/outlook-inbox.gif",
    "Templates", "icons/outlook-inbox.gif", "Deleted Items",
    "icons/outlook-trash.gif",};

  for (int i = 0, c = buttons.length; i < c; i += 2) {
    JButton button = new JButton(buttons[i]);
    try {
      button.setUI((ButtonUI)Class.forName(
        (String)UIManager.get("OutlookButtonUI")).newInstance());
    } catch (Exception e) {
      e.printStackTrace();
    }
    button.setIcon(new ImageIcon(OutlookBarMain.class
      .getResource(buttons[i + 1])));
    panel.add(button);
  }

  JScrollPane scroll = tabs.makeScrollPane(panel);
  tabs.addTab("", scroll);

  // this to test the UI gets notified of changes
  int index = tabs.indexOfComponent(scroll);
  tabs.setTitleAt(index, title);
  tabs.setToolTipTextAt(index, title + " Tooltip");
}
 
Example 5
public ChooseFont() {
  setLayout(new PercentLayout(PercentLayout.VERTICAL, 3));

  JFontChooser chooser = new JFontChooser();
  chooser.setSelectedFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 56));
  add("*", chooser);

  JButton button = new JButton("Click here to show JFontChooser");
  button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      selectFont(ChooseFont.this);
    }
  });
  add(button);
}
 
Example 6
protected void updateTabLayoutOrientation() {
  TabLayout layout = (TabLayout)tabPane.getLayout();
  int placement = tabPane.getTabPlacement();
  if (placement == JTabbedPane.TOP || placement == JTabbedPane.BOTTOM) {
    layout.setOrientation(PercentLayout.HORIZONTAL);
  } else {
    layout.setOrientation(PercentLayout.VERTICAL);
  }
}
 
Example 7
protected void updateLayout() {
  if (bar.getOrientation() == JButtonBar.HORIZONTAL) {
    bar.setLayout(new PercentLayout(PercentLayout.HORIZONTAL, 2));
  } else {
    bar.setLayout(new PercentLayout(PercentLayout.VERTICAL, 2));
  }
}
 
Example 8
protected void updateTabLayoutOrientation() {
  TabLayout layout = (TabLayout)tabPane.getLayout();
  int placement = tabPane.getTabPlacement();
  if (placement == JTabbedPane.TOP || placement == JTabbedPane.BOTTOM) {
    layout.setOrientation(PercentLayout.HORIZONTAL);
  } else {
    layout.setOrientation(PercentLayout.VERTICAL);
  }
}
 
Example 9
protected void tabAdded(final Component newTab) {
  TabButton button = (TabButton)tabToButton.get(newTab);
  if (button == null) {
    button = createTabButton();
    buttonToTab.put(button, newTab);
    tabToButton.put(newTab, button);
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        Component current = getVisibleComponent();
        Component target = newTab;
        
        // animate the tabPane if there is a current tab selected and if the
        // tabPane allows animation
        if (((JOutlookBar)tabPane).isAnimated() && current != target
          && current != null && target != null) {
      	try { // patch Manuel 16.03.2011   
      		if (animator != null) {
      			animator.stop();
      		}
      		animator = new PercentLayoutAnimator(tabPane,
      				(PercentLayout)tabPane.getLayout()) {
      			public void stop() {
      				super.stop();
      				tabPane.setSelectedComponent(newTab); // might throw an illegal argument exception
      				nextVisibleComponent = null;
      			}
      		};
      		nextVisibleComponent = newTab;
      		animator.setTargetPercent(current, 1.0f, 0.0f);
      		animator.setTargetPercent(newTab, 0.0f, 1.0f);
      		animator.start();
      	} catch (IllegalArgumentException ex) {
      		 nextVisibleComponent = null;
               tabPane.setSelectedComponent(newTab);
      	}
        } else {
          nextVisibleComponent = null;
          tabPane.setSelectedComponent(newTab);
        }
      }
    });
  } else {
    // the tab is already in the list, remove the button, it will be
    // added again later
    tabPane.remove(button);
  }

  // update the button with the tab information
  updateTabButtonAt(tabPane.indexOfComponent(newTab));

  int index = indexOfComponent(newTab);
  tabPane.add(button, index);

  // workaround for nullpointerexception in setRolloverTab
  // introduced by J2SE 5
  if (JVM.current().isOneDotFive()) {
    assureRectsCreated(tabPane.getTabCount());
  }
}
 
Example 10
protected void installComponents() {
  JLabel label;

  ResourceBundle bundle =
    ResourceBundle.getBundle(FontChooserUI.class.getName() + "RB");

  fontPanel = new JPanel(new PercentLayout(PercentLayout.VERTICAL, 2));
  fontPanel.add(
    label = new JLabel(bundle.getString("FontChooserUI.fontLabel")));
  fontPanel.add(fontField = new JTextField(25));
  fontField.setEditable(false);
  fontPanel.add(new JScrollPane(fontList = new JList()), "*");
  label.setLabelFor(fontList);
  label.setDisplayedMnemonic(
    bundle.getString("FontChooserUI.fontLabel.mnemonic").charAt(0));
  fontList.setVisibleRowCount(7);
  fontList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

  String[] fontFamilies = chooser.getModel().getFontFamilies(null);
  fontList.setListData(fontFamilies);

  fontSizePanel = new JPanel(new PercentLayout(PercentLayout.VERTICAL, 2));

  fontSizePanel.add(
    label = new JLabel(bundle.getString("FontChooserUI.styleLabel")));
  fontSizePanel.add(
    boldCheck = new JCheckBox(bundle.getString("FontChooserUI.style.bold")));
  fontSizePanel.add(
    italicCheck =
      new JCheckBox(bundle.getString("FontChooserUI.style.italic")));
  boldCheck.setMnemonic(
    bundle.getString("FontChooserUI.style.bold.mnemonic").charAt(0));
  italicCheck.setMnemonic(
    bundle.getString("FontChooserUI.style.italic.mnemonic").charAt(0));

  fontSizePanel.add(
    label = new JLabel(bundle.getString("FontChooserUI.sizeLabel")));

  label.setDisplayedMnemonic(
    bundle.getString("FontChooserUI.sizeLabel.mnemonic").charAt(0));

  fontSizePanel.add(fontSizeField = new JTextField());
  label.setLabelFor(fontSizeField);
  fontSizePanel.add(new JScrollPane(fontSizeList = new JList()), "*");
  
  int[] defaultFontSizes = chooser.getModel().getDefaultSizes();
  String[] sizes = new String[defaultFontSizes.length];
  for (int i = 0, c = sizes.length; i < c; i++) {
    sizes[i] = String.valueOf(defaultFontSizes[i]);
  }
  fontSizeList.setListData(sizes);
  fontSizeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  fontSizeList.setVisibleRowCount(2);

  chooser.setLayout(LookAndFeelTweaks.createBorderLayout());
  JPanel panel = new JPanel();
  panel.setLayout(LookAndFeelTweaks.createHorizontalPercentLayout());
  panel.add(fontPanel, "*");
  panel.add(fontSizePanel);
  chooser.add("Center", panel);

  previewPanel = new JTextArea();
  previewPanel.setPreferredSize(new Dimension(100, 40));
  previewPanel.setText(chooser.getModel().getPreviewMessage(null));
  JScrollPane scroll = new JScrollPane(previewPanel);
  chooser.add("South", scroll);
}
 
Example 11
protected void tabAdded(final Component newTab) {
  TabButton button = (TabButton)tabToButton.get(newTab);
  if (button == null) {
    button = createTabButton();
    
    // save the button original color,
    // later they would be restored if the button colors are not customized on
    // the OutlookBar
    button.putClientProperty(BUTTON_ORIGINAL_FOREGROUND, button.getForeground());
    button.putClientProperty(BUTTON_ORIGINAL_BACKGROUND, button.getBackground());
    
    buttonToTab.put(button, newTab);
    tabToButton.put(newTab, button);
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        final Component current = getVisibleComponent();
        Component target = newTab;

        // animate the tabPane if there is a current tab selected and if the
        // tabPane allows animation
        if (((JOutlookBar)tabPane).isAnimated() && current != target
          && current != null && target != null) {
          if (animator != null) {
            animator.stop();
          }
          animator = new PercentLayoutAnimator(tabPane,
            (PercentLayout)tabPane.getLayout()) {
            protected void complete() {
              super.complete();
              tabPane.setSelectedComponent(newTab);
              nextVisibleComponent = null;
              // ensure the no longer visible component has its constraint
              // reset to 100% in the case it becomes visible again without
              // animation
              if (current.getParent() == tabPane) {
                ((PercentLayout)tabPane.getLayout()).setConstraint(current,
                  "100%");
              }
            }
          };
          nextVisibleComponent = newTab;
          animator.setTargetPercent(current, 1.0f, 0.0f);
          animator.setTargetPercent(newTab, 0.0f, 1.0f);
          animator.start();
        } else {
          nextVisibleComponent = null;
          tabPane.setSelectedComponent(newTab);
        }
      }
    });
  } else {
    // the tab is already in the list, remove the button, it will be
    // added again later
    tabPane.remove(button);
  }

  // update the button with the tab information
  updateTabButtonAt(tabPane.indexOfComponent(newTab));

  int index = indexOfComponent(newTab);
  tabPane.add(button, index);

  // workaround for nullpointerexception in setRolloverTab
  // introduced by J2SE 5
  if (JVM.current().isOneDotFive()) {
    assureRectsCreated(tabPane.getTabCount());
  }
}