Java Code Examples for javax.swing.SwingConstants#TRAILING

The following examples show how to use javax.swing.SwingConstants#TRAILING . 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
Source File: HTMLLabel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setText(String value) {
    txt = value;
    
    Font font = getFont();
    Color fgColor = getForeground();
    Color bgColor = getBackground();
    
    value = value.replaceAll("\\n\\r|\\r\\n|\\n|\\r", "<br>"); //NOI18N
    value = value.replace("<code>", "<code style=\"font-size: " + font.getSize() + "pt;\">"); //NOI18N
    
    String fgText = "rgb(" + fgColor.getRed() + "," + fgColor.getGreen() + "," + fgColor.getBlue() + ")"; //NOI18N
    String bgText = isOpaque() ? "rgb(" + bgColor.getRed() + "," + bgColor.getGreen() + "," + bgColor.getBlue() + ")" : null; //NOI18N
    
    String alignText = null;
    switch (halign) {
        case SwingConstants.CENTER:
            alignText = "center"; //NOI18N
            break;
        case SwingConstants.RIGHT:
        case SwingConstants.TRAILING:
            alignText = "right"; //NOI18N
            break;
    }
    
    String bodyFlags = "text=\"" + fgText + "\""; //NOI18N
    if (bgText != null) bodyFlags += " bgcolor=\"" + bgText + "\""; //NOI18N
    if (alignText != null) bodyFlags += " align=\"" + alignText + "\""; //NOI18N
    
    super.setText("<html><body " + bodyFlags + " style=\"font-size: " + font.getSize() //NOI18N
                  + "pt; font-family: " + font.getName() + ";\">" + value + "</body></html>"); //NOI18N
}
 
Example 2
Source File: HTMLLabel.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void setText(String value) {
    txt = value;
    
    Font font = getFont();
    Color fgColor = getForeground();
    Color bgColor = getBackground();
    
    value = value.replaceAll("\\n\\r|\\r\\n|\\n|\\r", "<br>"); //NOI18N
    value = value.replace("<code>", "<code style=\"font-size: " + font.getSize() + "pt;\">"); //NOI18N
    
    String fgText = "rgb(" + fgColor.getRed() + "," + fgColor.getGreen() + "," + fgColor.getBlue() + ")"; //NOI18N
    String bgText = isOpaque() ? "rgb(" + bgColor.getRed() + "," + bgColor.getGreen() + "," + bgColor.getBlue() + ")" : null; //NOI18N
    
    String alignText = null;
    switch (halign) {
        case SwingConstants.CENTER:
            alignText = "center"; //NOI18N
            break;
        case SwingConstants.RIGHT:
        case SwingConstants.TRAILING:
            alignText = "right"; //NOI18N
            break;
    }
    
    String bodyFlags = "text=\"" + fgText + "\""; //NOI18N
    if (bgText != null) bodyFlags += " bgcolor=\"" + bgText + "\""; //NOI18N
    if (alignText != null) bodyFlags += " align=\"" + alignText + "\""; //NOI18N
    
    super.setText("<html><body " + bodyFlags + " style=\"font-size: " + font.getSize() //NOI18N
                  + "pt; font-family: " + font.getName() + ";\">" + value + "</body></html>"); //NOI18N
}
 
Example 3
Source File: PreferencesFrame.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void addField(JPanel p, GridBagConstraints c, int y, String lbl, JComponent field) {
    c.gridy = y;
    JLabel l = new JLabel(lbl, SwingConstants.TRAILING);
    l.setLabelFor(field);
    c.anchor = GridBagConstraints.LINE_END;
    c.gridx = 0;
    p.add(l, c);
    c.anchor = GridBagConstraints.LINE_START;
    c.gridx = 1;
    p.add(field, c);
}
 
Example 4
Source File: IKTasksTableModel.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
public void setValue(Object value) {
   IKTasksValueCell obj = (IKTasksValueCell)value;
   super.setFont(regularFont); // reset
   switch(obj.tasks.getValueType(obj.index)) {
      case FromFile: super.setValue(obj.tasks.isValidValue(obj.index) ?  IKTasksTableModel.FromFileStr : IKTasksTableModel.InvalidFromFileStr); break;
      case DefaultValue: super.setValue(((Double)obj.tasks.getDefaultValue(obj.index))); break;
      case ManualValue: super.setValue((Double)obj.tasks.getValue(obj.index)); super.setFont(boldFont); break;
   }
   super.setHorizontalAlignment(SwingConstants.TRAILING);
}
 
Example 5
Source File: LayoutStyle.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
private boolean isLeftAligned(AbstractButton button, int position) {
	if (position == SwingConstants.WEST) {
		boolean ltr = button.getComponentOrientation().isLeftToRight();
		int hAlign = button.getHorizontalAlignment();
		return ((ltr && (hAlign == SwingConstants.LEFT || hAlign == SwingConstants.LEADING))
				|| (!ltr && (hAlign == SwingConstants.TRAILING)));
	}
	return false;
}
 
Example 6
Source File: LayoutStyle.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
private boolean isRightAligned(AbstractButton button, int position) {
	if (position == SwingConstants.EAST) {
		boolean ltr = button.getComponentOrientation().isLeftToRight();
		int hAlign = button.getHorizontalAlignment();
		return ((ltr && (hAlign == SwingConstants.RIGHT || hAlign == SwingConstants.TRAILING))
				|| (!ltr && (hAlign == SwingConstants.LEADING)));
	}
	return false;
}
 
Example 7
Source File: StyleEditor.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
static boolean validHorizontalKey(int key) {
  return ((key == SwingConstants.LEFT)    ||
   (key == SwingConstants.CENTER)  ||
   (key == SwingConstants.RIGHT)   ||
   (key == SwingConstants.LEADING) ||
   (key == SwingConstants.TRAILING));
}
 
Example 8
Source File: IKTasksTableModel.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
public void setValue(Object value) {
   IKTasksWeightCell obj = (IKTasksWeightCell)value;
   if(obj.tasks.isLocked(obj.index)) super.setValue(IKTasksTableModel.LockedStr);
   else super.setValue((Double)obj.tasks.getWeight(obj.index));
   super.setHorizontalAlignment(SwingConstants.TRAILING);
}
 
Example 9
Source File: MainFrame.java    From desktopclient-java with GNU General Public License v3.0 4 votes vote down vote up
private static WebPanel createListPanel(final WebTable list,
                                        String overlayText,
                                        WebToggleButton button) {
    // overlay for empty list
    WebOverlay listOverlay = new WebOverlay(list);
    listOverlay.setOverlayMargin(20);
    final WebTextArea overlayArea = new WebTextArea();
    overlayArea.setText(overlayText);
    overlayArea.setLineWrap(true);
    overlayArea.setWrapStyleWord(true);
    overlayArea.setMargin(View.MARGIN_DEFAULT);
    overlayArea.setFontSize(View.FONT_SIZE_BIG);
    overlayArea.setEditable(false);
    BorderPainter<WebTextArea> borderPainter = new BorderPainter<>(Color.LIGHT_GRAY);
    borderPainter.setRound(15);
    overlayArea.setPainter(borderPainter);
    list.getModel().addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            overlayArea.setVisible(list.getModel().getRowCount() == 0);
        }
    });
    overlayArea.setVisible(list.getModel().getRowCount() == 0);
    listOverlay.addOverlay(overlayArea, SwingConstants.CENTER, SwingConstants.CENTER);

    WebScrollPane scrollPane = new ComponentUtils.ScrollPane(listOverlay);
    scrollPane.setDrawBorder(false);

    // button as overlay
    button.setOpaque(false);
    button.setUndecorated(true);
    WebOverlay chatListOverlay = new WebOverlay(scrollPane,
            button, SwingConstants.TRAILING, SwingConstants.BOTTOM);
    chatListOverlay.setOverlayMargin(0, 0, View.GAP_BIG, View.GAP_BIG + SCROLL_BAR_WIDTH);
    // fixing overlay button paint bug on startup, dont wanna know whats happening here
    SwingUtils.delayInvokeLater(0, new Runnable() {
        @Override
        public void run() {
            TooltipManager.showOneTimeTooltip(list, new Point(1,1), "");
        }
    });

    return chatListOverlay;
}
 
Example 10
Source File: ExportStatusDialog.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
private void initGUI(String impExpTitle, String impExpMessage) {
	setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
	fileName = new JLabel(impExpMessage);
	fileName.setFont(fileName.getFont().deriveFont(Font.BOLD));
	messageLabel = new JLabel(" ");
	cancelButton = new JButton(Language.I18N.getString("common.button.cancel"));
	featureLabel = new JLabel(Language.I18N.getString("common.status.dialog.featureCounter"));
	appearanceLabel = new JLabel(Language.I18N.getString("common.status.dialog.appearanceCounter"));
	textureLabel = new JLabel(Language.I18N.getString("common.status.dialog.textureCounter"));

	featureCounterLabel = new JLabel("0", SwingConstants.TRAILING);
	appearanceCounterLabel = new JLabel("0", SwingConstants.TRAILING);
	textureCounterLabel = new JLabel("0", SwingConstants.TRAILING);
	featureCounterLabel.setPreferredSize(new Dimension(100, featureLabel.getPreferredSize().height));
	appearanceCounterLabel.setPreferredSize(new Dimension(100, appearanceLabel.getPreferredSize().height));
	textureCounterLabel.setPreferredSize(new Dimension(100, textureLabel.getPreferredSize().height));

	progressBar = new JProgressBar();

	setLayout(new GridBagLayout()); 
	{			
		main = new JPanel();
		add(main, GuiUtil.setConstraints(0,0,1.0,0.0,GridBagConstraints.BOTH,5,5,5,5));
		main.setLayout(new GridBagLayout());
		{
			int gridY = 0;

			main.add(fileName, GuiUtil.setConstraints(0,gridY++,0.0,0,GridBagConstraints.HORIZONTAL,5,5,5,5));
			main.add(messageLabel, GuiUtil.setConstraints(0,gridY++,0.0,0,GridBagConstraints.HORIZONTAL,5,5,0,5));
			main.add(progressBar, GuiUtil.setConstraints(0,gridY++,1.0,0.0,GridBagConstraints.HORIZONTAL,0,5,5,5));

			details = new JLabel("Details");
			main.add(details, GuiUtil.setConstraints(0,gridY++,1.0,0.0,GridBagConstraints.HORIZONTAL,5,5,0,5));

			row = new JPanel();
			row.setBackground(new Color(255, 255, 255));
			row.setBorder(BorderFactory.createEtchedBorder());
			main.add(row, GuiUtil.setConstraints(0,gridY++,1.0,0.0,GridBagConstraints.BOTH,0,5,5,5));
			row.setLayout(new GridBagLayout());
			{
				row.add(featureLabel, GuiUtil.setConstraints(0,0,0.0,0.0,GridBagConstraints.HORIZONTAL,5,5,1,5));
				row.add(featureCounterLabel, GuiUtil.setConstraints(1,0,1.0,0.0,GridBagConstraints.HORIZONTAL,5,5,1,5));
				row.add(appearanceLabel, GuiUtil.setConstraints(0,1,0.0,0.0,GridBagConstraints.HORIZONTAL,1,5,1,5));
				row.add(appearanceCounterLabel, GuiUtil.setConstraints(1,1,1.0,0.0,GridBagConstraints.HORIZONTAL,1,5,1,5));
				row.add(textureLabel, GuiUtil.setConstraints(0,2,0.0,0.0,GridBagConstraints.HORIZONTAL,1,5,5,5));
				row.add(textureCounterLabel, GuiUtil.setConstraints(1,2,1.0,0.0,GridBagConstraints.HORIZONTAL,1,5,5,5));

				if (showTileCounter) {
					tileLabel = new JLabel(Language.I18N.getString("common.status.dialog.tileCounter"));
					tileCounterLabel = new JLabel("n/a", SwingConstants.TRAILING);
					tileCounterLabel.setPreferredSize(new Dimension(100, tileCounterLabel.getPreferredSize().height));

					row.add(tileLabel, GuiUtil.setConstraints(0,3,0.0,0.0,GridBagConstraints.HORIZONTAL,1,5,5,5));
					row.add(tileCounterLabel, GuiUtil.setConstraints(1,3,1.0,0.0,GridBagConstraints.HORIZONTAL,1,5,5,5));
				}
			}
		}

		add(cancelButton, GuiUtil.setConstraints(0,1,0.0,0.5,GridBagConstraints.NONE,5,5,5,5));
	}

	pack();
	progressBar.setIndeterminate(true);

	addWindowListener(new WindowAdapter() {
		public void windowClosed(WindowEvent e) {
			eventDispatcher.removeEventHandler(ExportStatusDialog.this);
		}
	});
}
 
Example 11
Source File: XMLValidationStatusDialog.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
private void initGUI(String windowTitle, 
		String statusTitle, 
		String statusMessage, 
		String statusDetails, 
		boolean setButton) {
	
	if (statusTitle == null)
		statusTitle = "";
	
	if (statusMessage == null)
		statusMessage = "";
	
	String[] details = null;
	if (statusDetails != null)
		details = statusDetails.split("<br\\s*/*>");
	
	setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
	titleLabel = new JLabel(statusTitle);
	titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD));
	messageLabel = new JLabel(statusMessage);
	fileCounter = new JLabel(Language.I18N.getString("common.status.dialog.fileCounter"));
	fileCounterLabel = new JLabel("n/a", SwingConstants.TRAILING);
	button = new JButton(Language.I18N.getString("common.button.cancel"));		
	progressBar = new JProgressBar();

	setLayout(new GridBagLayout()); {
		main = new JPanel();
		add(main, GuiUtil.setConstraints(0,0,1.0,0.0,GridBagConstraints.BOTH,5,5,5,5));
		main.setLayout(new GridBagLayout());
		{
			main.add(titleLabel, GuiUtil.setConstraints(0,0,0.0,0.5,GridBagConstraints.HORIZONTAL,5,5,5,5));
			main.add(messageLabel, GuiUtil.setConstraints(0,1,0.0,0.5,GridBagConstraints.HORIZONTAL,5,5,0,5));
			main.add(progressBar, GuiUtil.setConstraints(0,2,1.0,0.0,GridBagConstraints.HORIZONTAL,0,5,5,5));

			if (details != null) {
				detailsLabel = new JLabel("Details");
				main.add(detailsLabel, GuiUtil.setConstraints(0,3,1.0,0.0,GridBagConstraints.HORIZONTAL,5,5,0,5));

				row = new JPanel();
				row.setBackground(new Color(255, 255, 255));
				row.setBorder(BorderFactory.createEtchedBorder());
				main.add(row, GuiUtil.setConstraints(0,4,1.0,0.0,GridBagConstraints.BOTH,0,5,5,5));
				row.setLayout(new GridBagLayout());
				{				
					int i = 0;
					for ( ; i < details.length; ++i) {
						JLabel detail = new JLabel(details[i]);
						detail.setBackground(row.getBackground());
						GridBagConstraints c = GuiUtil.setConstraints(0,i,1.0,0.0,GridBagConstraints.HORIZONTAL,i == 0 ? 5 : 2,5,i == details.length - 1 ? 5 : 0,5);
						c.gridwidth = 2;
						row.add(detail, c);
					}
					
					row.add(fileCounter, GuiUtil.setConstraints(0,i+1,1.0,0.0,GridBagConstraints.HORIZONTAL,1,5,5,5));
					row.add(fileCounterLabel, GuiUtil.setConstraints(1,i+1,1.0,0.0,GridBagConstraints.HORIZONTAL,1,5,5,5));
				}
			}
		}

		if (setButton)
			add(button, GuiUtil.setConstraints(0,1,0.0,0.0,GridBagConstraints.NONE,5,5,5,5));

		pack();
		progressBar.setIndeterminate(true);
		
		addWindowListener(new WindowAdapter() {
			public void windowClosed(WindowEvent e) {
				if (eventDispatcher != null)
					eventDispatcher.removeEventHandler(XMLValidationStatusDialog.this);
			}
		});
	}
}
 
Example 12
Source File: ImportStatusDialog.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
private void initGUI(String impExpTitle, String impExpMessage) {
	setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
	fileName = new JLabel(impExpMessage);
	fileName.setFont(fileName.getFont().deriveFont(Font.BOLD));
	mesageLabel = new JLabel(" ");
	cancelButton = new JButton(Language.I18N.getString("common.button.cancel"));
	featureLabel = new JLabel(Language.I18N.getString("common.status.dialog.featureCounter"));
	appearanceLabel = new JLabel(Language.I18N.getString("common.status.dialog.appearanceCounter"));
	textureLabel = new JLabel(Language.I18N.getString("common.status.dialog.textureCounter"));
	fileCounter = new JLabel(Language.I18N.getString("common.status.dialog.fileCounter"));
	fileCounterLabel = new JLabel("n/a", SwingConstants.TRAILING);
	featureCounterLabel = new JLabel("0", SwingConstants.TRAILING);
	appearanceCounterLabel = new JLabel("0", SwingConstants.TRAILING);
	textureCounterLabel = new JLabel("0", SwingConstants.TRAILING);

	featureCounterLabel.setPreferredSize(new Dimension(100, featureLabel.getPreferredSize().height));
	appearanceCounterLabel.setPreferredSize(new Dimension(100, appearanceLabel.getPreferredSize().height));
	textureCounterLabel.setPreferredSize(new Dimension(100, textureLabel.getPreferredSize().height));

	progressBar = new JProgressBar();

	setLayout(new GridBagLayout()); 
	{			
		main = new JPanel();
		add(main, GuiUtil.setConstraints(0,0,1.0,0.0,GridBagConstraints.BOTH,5,5,5,5));
		main.setLayout(new GridBagLayout());
		{
			main.add(fileName, GuiUtil.setConstraints(0,0,0.0,0,GridBagConstraints.HORIZONTAL,5,5,5,5));
			main.add(mesageLabel, GuiUtil.setConstraints(0,1,0.0,0,GridBagConstraints.HORIZONTAL,5,5,0,5));
			main.add(progressBar, GuiUtil.setConstraints(0,2,1.0,0.0,GridBagConstraints.HORIZONTAL,0,5,5,5));

			details = new JLabel("Details");
			main.add(details, GuiUtil.setConstraints(0,3,1.0,0.0,GridBagConstraints.HORIZONTAL,5,5,0,5));

			row = new JPanel();
			row.setBackground(new Color(255, 255, 255));
			row.setBorder(BorderFactory.createEtchedBorder());
			main.add(row, GuiUtil.setConstraints(0,4,1.0,0.0,GridBagConstraints.BOTH,0,5,5,5));
			row.setLayout(new GridBagLayout());
			{
				row.add(featureLabel, GuiUtil.setConstraints(0,0,0.0,0.0,GridBagConstraints.HORIZONTAL,5,5,1,5));
				row.add(featureCounterLabel, GuiUtil.setConstraints(1,0,1.0,0.0,GridBagConstraints.HORIZONTAL,5,5,1,5));
				row.add(appearanceLabel, GuiUtil.setConstraints(0,1,0.0,0.0,GridBagConstraints.HORIZONTAL,1,5,1,5));
				row.add(appearanceCounterLabel, GuiUtil.setConstraints(1,1,1.0,0.0,GridBagConstraints.HORIZONTAL,1,5,1,5));
				row.add(textureLabel, GuiUtil.setConstraints(0,2,0.0,0.0,GridBagConstraints.HORIZONTAL,1,5,5,5));
				row.add(textureCounterLabel, GuiUtil.setConstraints(1,2,1.0,0.0,GridBagConstraints.HORIZONTAL,1,5,5,5));
				row.add(fileCounter, GuiUtil.setConstraints(0,3,1.0,0.0,GridBagConstraints.HORIZONTAL,1,5,5,5));
				row.add(fileCounterLabel, GuiUtil.setConstraints(1,3,1.0,0.0,GridBagConstraints.HORIZONTAL,1,5,5,5));
			}
		}

		add(cancelButton, GuiUtil.setConstraints(0,1,0.0,0.5,GridBagConstraints.NONE,5,5,5,5));
	}

	pack();
	progressBar.setIndeterminate(true);

	addWindowListener(new WindowAdapter() {
		public void windowClosed(WindowEvent e) {
			eventDispatcher.removeEventHandler(ImportStatusDialog.this);
		}
	});
}